我需要将值绑定到ui-select ng-model
带有来自JSON响应的图标的ui-select显示类别
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RandomSpawn : MonoBehaviour {
public List<GameObject> Spawnables;
public Terrain spawnLand;
public float spawnWait = 1f;
public int numPer = 1;
public bool enableSpawning =true;
float minx,maxx,minz,maxz,waiter = 1f;
// Use this for initialization
void Start () {
minx = spawnLand.transform.position.x+2;
maxx = spawnLand.terrainData.size.x + minx-4;
minz = spawnLand.transform.position.z+2;
maxz = spawnLand.terrainData.size.z + minz-4;
}
void Update(){
waiter -= Time.deltaTime;
if (waiter<=0) {
waiter = spawnWait;
if (enableSpawning) {
Spawn ();
}
}
}
void Spawn()
{
for (int i = 0; i < numPer; i++) {
Vector3 loc = new Vector3 (Random.Range (minx, maxx), 0, Random.Range (minz, maxz));
GameObject go = (GameObject)Instantiate (Spawnables[Random.Range (0,Spawnables.Count)],new Vector3(0,0,0),new Quaternion(0,0,0,0));
NavMeshHit closestHit;
if( NavMesh.SamplePosition( loc, out closestHit, 500, 1 ) ){
go.transform.position = closestHit.position;
go.AddComponent<NavMeshAgent>();
//TODO
}
else{
Debug.Log("...");
}
}
}
}
我的分类回复是这样的:
<ui-select ng-model="trans.cat" >
<ui-select-match placeholder="Select a categorie...">
<img ng-src="{{$select.selected.caticon}}" class="icons"/>
{{$select.selected.catname}}
</ui-select-match>
<ui-select-choices repeat=" cat in categorie | filter: $select.search">
<img ng-src="{{cat.caticon}}" class="icons"/>{{cat.catname}}
</ui-select-choices>
我需要将catvalue绑定到ng-model,我尝试了很多解决方案,但我不断得到[object object]或者未定义结果。
我的GET请求:
{"Categorie":[{"catname":"Taxi","caticon":"img/ic_taxi.png","catvalue":1,"_id":"59eb8faa0a0c7534403cbd0a","__v":0}]
答案 0 :(得分:0)
我认为你需要这个,
<ui-select-choices repeat="cat in categorie.Categorie">
<img ng-src="{{cat.caticon}}" class="icons"/>
<div ng-bind="val.catname "></div>
</ui-select-cfhoices>
<强> DEMO 强>